<!DOCTYPE html>
<html lang="en">


{include file="Public/head"}

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">优惠券列表
                            <a href="javascript:history.go(-1)" style="float: right" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
                        </div>
                        </div>
                        <div class="widget-body  am-fr">
                            <div class="navbar navbar-default">
                                <form action="" id="search-form" class="navbar-form form-inline" method="post">
                                    <div class="form-group">
                                        <select name="level_id" id="level_id" class="form-control">
                                            <option value="0">所有会员</option>
                                            {foreach name="level" item="vo"}
                                            <option value="{$vo['level_id']}"> {$vo['level_name']}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                    <input type="hidden" name="cid" id="cid" value="{$cid}">
                                    <button type="button" onclick="doconfirm(1)"  id="button-filter" class="btn btn-info">确定发送优惠券</button>
                                </form>
                            </div>
                            <div class="navbar navbar-default">
                                <form action="{:url('Coupon/send_coupon')}" id="search-form2" class="navbar-form form-inline" method="post">
                                    <div class="form-group">
                                        <label class="control-label" for="input-mobile">手机号码</label>
                                        <div class="input-group">
                                            <input type="text" name="mobile" value="" placeholder="手机号码" id="input-mobile" class="form-control">
                                            <input type="hidden" name="cid"  value="{$cid}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label" for="input-email">email</label>
                                        <div class="input-group">
                                            <input type="text" name="email" value="" placeholder="email" id="input-email" class="form-control">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label" for="input-order-id">昵称关键词</label>
                                        <div class="input-group">
                                            <input type="text" name="nickname"  placeholder="搜索词" id="input-order-id" class="form-control">
                                        </div>
                                    </div>
                                    <button type="submit"  id="button-filter search-order" class="btn btn-primary"><i class="fa fa-search"></i>查找</button>
                                    <button type="button" onclick="doconfirm(2)" class="btn btn-info pull-right">确定发送优惠券</button>
                                </form>
                            </div>

<!--内容-->
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                    <td class="text-left"><input type="checkbox" onclick="$('input[name*=\'user_id\']').prop('checked', this.checked);">全选</td>
                                    <td class="text-left">会员ID</td>
                                    <td class="text-left">会员等级</td>
                                    <td class="text-left">会员昵称 </td>
                                    <td class="text-left">手机</td>
                                    <td class="text-left">邮箱</td>
                                    <td class="text-left">操作</td>
                                    </tr>
                                    </thead>
                                    <tbody id="goos_table">
                                    {volist name="userList" id="list"}
                                        <tr>
                                            <td class="text-left">
                                                <input type="checkbox" name="user_id" value="{$list.user_id}"/>
                                            </td>
                                            <td class="text-left">{$list.user_id}</td>
                                            <td class="text-left">{$user_level[$list['level']]}</td>
                                            <td class="text-left">
                                                {if condition=" $list['nickname'] eq null"}
                                                    {if condition=" $list['oauth'] eq 'weixin'"}微信用户{/if}
                                                    {if condition=" $list['oauth'] eq 'weibo'"}微博用户{/if}
                                                    {if condition=" $list['oauth'] eq 'alipay'"}支付宝用户{/if}
                                                    {if condition=" $list['oauth'] eq 'qq'"}QQ用户{/if}
                                                    {else /}
                                                    {$list.nickname}
                                                {/if}
                                            </td>
                                            <td class="text-left">{$list.mobile}</td>
                                            <td class="text-left">{$list.email}</td>
                                            <td><a href="javascript:void(0)" onclick="javascript:$(this).parent().parent().remove();">删除</a></td>
                                        </tr>
                                    {/volist}
                                    </tbody>
                                </table>
                            </div>
                            <div class="am-u-lg-10 am-cf">

                                <div class="am-fr">
                                    <ul class="am-pagination tpl-pagination">
                                        {$userList->render()}
                                    </ul>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
{include file='Public:script'}
<script>

    // 删除按钮
    function delfun(obj) {
        layer.confirm("确定删除？", {btn: ["确定","取消"], shade: 0.5}, function(){
            // 删除权限组
            $.post($(obj).attr('data-url'), function(res) {
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 2});
                    return false;
                }

                layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 1}, function() {
                    layer.closeAll('page');
                    location.reload();
                });
            });
        }, function () {});
    }

//发送优惠券
    function doconfirm(obj){
        var param = new Object();
        param['cid']=$('#cid').val();
        if(obj==1){       //发送1
            param['level_id']=$("#level_id option:selected").val();
        }else if(obj==2) {  //发送2
            if ($("input[type='checkbox']:checked").length == 0) {
                layer.alert('请选择会员', {icon: 2}); //alert('请选择商品');
                return false;
            } else {
                var user_id = '';
                $('input[name="user_id"]:checked').each(function () {
                    user_id += $(this).val() + ',';
                });
                param['user_id'] = user_id;
            }
        }
            $.post("{:url('Coupon/fafang')}",param, function(res) {
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 2});
                    return false;
                }

                layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function() {
                    location.href = "{:url('index')}";
                });
            });
    }

</script>
